# -*- coding: utf-8 -*-

# Created on 26/10/2010

# Copyright (C) 2010  Sergio Rodrigo

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


import pygame

from core.Scoreboard import Scoreboard
from core.TextRenderer import TextRenderer

class PongScoreboard(Scoreboard):
    """ Scoreboard of the pong.
    
    * Methods:
    draw(self, scene)
    
    * Member variables:
    screen -- Screen (scene) where the graphic is displayed
    textRenderer -- TextRenderer object to render the scores
    fontText -- String text of the font
    fontSize -- Integer size of the font
    
    """
    def __init__(self):
        Scoreboard.__init__(self)
        self.screen = None
        self.fontText = None
        self.fontSize = 50
        self.textRenderer = TextRenderer(self.fontText, self.fontSize)
    
    def draw(self, scene):
        if len(self.scores) == 2:
            #pygame.draw.rect(self.screen, (255, 255, 255), (220,  10,   200,   50))
            #pygame.draw.rect(self.screen, (0, 0, 0), (225,  15,   190,   40))
            middle = self.screen.get_width() / 2
            space = 30
            score1 = str(self.scores[0].value)
            score2 = str(self.scores[1].value)
            scoreSeparator = ":"
            self.textRenderer.screen = self.screen
            # draw score 1
            self.textRenderer.render( \
                self.screen, \
                score1, \
                (255, 255, 255), \
                (middle - space - (self.textRenderer.getTextWidth(score1) / 2), 0))
            # draw score separator
            self.textRenderer.render( \
                self.screen, \
                scoreSeparator, \
                (255, 255, 255), \
                (middle - (self.textRenderer.getTextWidth(scoreSeparator) / 2), 0))
            # draw score 2
            self.textRenderer.render( \
                self.screen, \
                score2, \
                (255, 255, 255), \
                (middle + space - (self.textRenderer.getTextWidth(score2) / 2), 0))
            '''
            font = pygame.font.Font(None, 36)
            score1 = font.render(str(self.scores[0].value), 1, (255, 255, 255))
            score2 = font.render(str(self.scores[1].value), 1, (255, 255, 255))
            middle = self.screen.get_width() / 2
            space = 30
            self.screen.blit(score1, (middle - space, 0))
            self.screen.blit(score2, (middle + space, 0))'''
            
# eof